package pure.engine.world 
{
	import pure.engine.model.Model2D;
	import pure.engine.core.ns_despair;
	use namespace ns_despair;
	
	/**
	 * 区块
	 * [Author] - PURE
	 * 
	 */
final internal class Region 
{	

	
	/**
	 * 加入
	 * 
	 * [Param] - model  模型
	 */
	final internal function add(model:Model2D):void
	{
		m_modelList[m_length++] = model;
	}
	
	
	/**
	 * 移除
	 * 
	 * [Param] - model  模型
	 */
	final internal function remove(model:Model2D):void
	{
		var index:int = m_modelList.indexOf(model);
		
		m_modelList[index] = m_modelList[--m_length];
		m_modelList.pop();
	}
	
	
	/**
	 * 清空
	 */
	final internal function clear():void
	{
		while (--m_length > -1)
		{
			m_modelList[m_length].destroy();
		}
		m_modelList.length = m_length = 0;
	}
	
	
	final internal function accumulate():void
	{
		
	}
	
	
	/**
	 * 回收
	 */
	final internal function recycle():void
	{
		while (--m_length > -1)
		{
			m_modelList[m_length].destroy()
		}
		m_data = m_modelList.length = m_length = 0;
		m_cachedRegionList.push(this);
	}
	
	
	/**
	 * 获取模型区块
	 */
	internal static function getRegion():Region
	{
		if (m_cachedRegionList[0])
		{
			return m_cachedRegionList.pop();
		}
		return new Region();
	}
	
	
	
	
	
	
	
	//======================
	// Member
	//======================
	
	
	internal static var m_cachedRegionList:Array = [];
	
	//internal static var m_cachedModelList:Array = [];
	//
	//internal static var m_cachedModelLength:int;
	//
	//
	//internal var m_modelList:Vector.<Model2D> = new Vector.<Model2D>();
	internal var m_modelList:Array = [];
	
	internal var m_length:int;

	internal var m_data:int;
}

}